package com.heima.wemedia.feign;

import com.heima.apis.admin.IAdminAuthNewsClient;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmSensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.ManualReviewScanService;
import com.heima.wemedia.service.WmSensitiveService;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class IAdminClientController implements IAdminAuthNewsClient {

    @Autowired
    private ManualReviewScanService manualReviewScanService;

    @Autowired
    private WmUserService wmUserService;
    /**
     * 获取所有文章列表
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/api/v1/auth/list_vo")
    public ResponseResult listVo(@RequestBody NewsAuthDto newsAuthDto){
        return manualReviewScanService.listVo(newsAuthDto);
    }

    /**
     * 获取文章详情
     * @param wmNewsId
     * @return
     */
    @GetMapping("/api/v1/auth/one_vo/{id}")
    public ResponseResult onrVo(@PathVariable("id") Integer wmNewsId){
        return manualReviewScanService.oneVo(wmNewsId);
    }

    /**
     * 审核文章 不通过
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/api/v1/auth/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto newsAuthDto){
        return manualReviewScanService.authFail(newsAuthDto);
    }

    /**
     * 审核文章 通过
     * @param newsAuthDto
     * @return
     */
    @PostMapping("/api/v1/auth/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto newsAuthDto){
        return manualReviewScanService.authPass(newsAuthDto);
    }

    @PostMapping("/api/v1/wmnews/creatUser")
    public ResponseResult creatUser(@RequestBody WmUser wmUser){
        return wmUserService.creatUser(wmUser);
    };
    @Autowired
    private WmSensitiveService sensitiveService;
    @Override
    @DeleteMapping("/api/v1/WmSensitive/del/{id}")
    public ResponseResult del(Integer id) {
        sensitiveService.removeById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @Override
    @PostMapping("/api/v1/WmSensitive/list")
    public PageResponseResult list(WmSensitiveDto wmSensitiveDto) {

        return sensitiveService.listPage(wmSensitiveDto);
    }

    @Override
    @PostMapping("/api/v1/WmSensitive/save")
    public ResponseResult save(WmSensitive wmSensitive) {

        return sensitiveService.add(wmSensitive);
    }

    @Override
    @PostMapping("/api/v1/WmSensitive/update")
    public ResponseResult update(WmSensitive wmSensitive) {
        try {
            sensitiveService.updateById(wmSensitive);
        } catch (Exception e) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
